<?php

/**
 * Description of User_Question
 *
 * @author fabrice
 */
class Model_User_Question extends PDO_Mysql {
    
    protected $_name = 'user_question';
    protected $_primary = 'id_user_question';

    /**
     * Recupere tout les questions par utilisateur
     * @return <array>
     */
    public function getQuestionByUserId($id_user) {

        $sql = "SELECT * FROM " . $this->_name ." WHERE id_user=" . $id_user;
        $result = $this->pquery($sql);
        $row = $this->pfetchAll($result);
        return $row;
    }
    
    /**
     * Recupere tout les utilisateurs par questions
     * @return <array>
     */
    public function getUsersByQuestionId($id_question) {

        $sql = 'SELECT * FROM ' . $this->_name . " WHERE id_question=" . $id_question;
        $result = $this->pquery($sql);
        $row = $this->pfetchAll($result);
        return $row;
    }
    
    public function getQuestion($id_question, $id_user) {
        
        $sql = 'SELECT * FROM ' . $this->_name . " WHERE id_question=" . $id_question. " AND id_user=" . $id_user;
        $result = $this->pquery($sql);
        $row = $this->pfetch($result);
        return $row;
    }

    /**
     * Insert user_question
     * @param <int> $id_question
     * @param <int> $id_user
     * @return <bool> $row
     */
    public function setUserQuestion($id_question, $id_user) {

        $sql = 'INSERT INTO ' . $this->_name . ' (id_user_question,id_question,id_user)' .
                ' VALUES (:id_user_question,:id_question,:id_user)';
        $data = array(
            'id_user_question' => NULL,
            ':id_question' => $id_question,
            ':id_user' => $id_user
        );
        $row = $this->pinsert($sql, $data, 'id_user_question');
        return $row;
    }
}

?>